package com.longge.wechat.controller.wx;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.longge.wechat.communication.Poster;
import com.longge.wechat.message.resp.Image;
import com.longge.wechat.message.resp.RespImageMessage;
import com.longge.wechat.utils.XmlUtil;



@Controller
public class RespImageController {

	@RequestMapping(value = "/image.do", method = RequestMethod.POST)
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		Image image = new Image();
		image.setMediaId((String) request.getAttribute("mediaId"));
		
		RespImageMessage message = new RespImageMessage(
				(String) request.getAttribute("openId"),
				(String) request.getAttribute("from"));
		message.setImage(image);
		Poster.post(response, XmlUtil.getInstance().bean2xml(message,"Image",image));
	}
}
